package com.xli.mis.datasource.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xli.mis.datasource.entity.DataSource;
import com.xli.mis.datasource.mapper.DataSourceMapper;
import com.xli.mis.datasource.service.IDataSourceService;
import jakarta.validation.constraints.NotNull;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSource> implements IDataSourceService {

    @Override
    public boolean insert(DataSource dataSource) {
        return this.save(dataSource);
    }

    @Override
    public boolean delete(Long id) {
        return this.removeById(id);
    }

    @Override
    public boolean update(DataSource dataSource) {
        return this.updateById(dataSource);
    }

    @Override
    public DataSource find(Long id) {
        return this.getById(id);
    }

    @Override
    public long findCount(QueryWrapper<DataSource> qw) {
        return this.count(qw);
    }

    @Override
    public List<DataSource> findList(QueryWrapper<DataSource> qw) {
        return this.list(qw);
    }

    @Override
    public Page<DataSource> findList(QueryWrapper<DataSource> qw, long current, long size) {
        return this.page(new Page<>(current, size), qw);
    }

    @Override
    public DataSource findByName(@NotNull String name) {
        QueryWrapper<DataSource> qw = new QueryWrapper<>();
        qw.lambda().eq(DataSource::getDs_name, name);
        return this.getOne(qw, false);
    }

    @Override
    public boolean isExists(QueryWrapper<DataSource> qw) {
        return (this.count(qw) > 0);
    }
}
